package com.begye.smartloan.apptest.gongong

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.begye.smartloan.apptest.MyApplication
import com.begye.smartloan.apptest.R
import com.begye.smartloan.apptest.tool.DingDangTool
import com.begye.smartloan.apptest.tool.IApiProcessCallback
import com.begye.smartloan.apptest.tool.LoginTool
import com.begye.smartloan.apptest.tool.PageTagTool
import com.begye.smartloan.apptest.tool.SysConfigTool
import com.begye.smartloan.apptest.tool.doPostRequest
import org.json.JSONArray
import org.json.JSONObject

class YongHuLiuChengViewModel : ViewModel() {

    var pageTitle: String = ""
    var pageTag: String = ""
    var pageUrl: String = ""

    private val _loadingStateLiveData = MutableLiveData<Boolean>()
    val onLoadingStateLiveData get() = _loadingStateLiveData

    private val _hasOrderStatusLiveData = MutableLiveData<PageTagTool>()
    val onHasOrderStatusLiveData get() = _hasOrderStatusLiveData

    private val _doneFillLiveData = MutableLiveData<List<JSONObject>>()
    val onDoneFillLiveData get() = _doneFillLiveData

    private val _doingLianXiRenFillLiveData =
        MutableLiveData<Pair<JSONObject, List<List<JSONObject>>>>()
    val onDoingLianXiRenFillLiveData get() = _doingLianXiRenFillLiveData

    private val _doingBangKaFillLiveData = MutableLiveData<JSONObject>()
    val onDoingBangKaFillLiveData get() = _doingBangKaFillLiveData

    private val _doingFillLiveData = MutableLiveData<Pair<JSONObject, List<JSONObject>>>()
    val onDoingFillLiveData get() = _doingFillLiveData

    private val _doingLianXiRenPageLiveData = MutableLiveData<Boolean>()
    val onDoingLianXiRenPageLiveData get() = _doingLianXiRenPageLiveData

    private val _doingBangKaFrPageLiveData = MutableLiveData<Boolean>()
    val onDoingBangKaFrPageLiveData get() = _doingBangKaFrPageLiveData

    private val _doingDocumentPageLiveData = MutableLiveData<Boolean>()
    val onDoingDocumentPageLiveData get() = _doingDocumentPageLiveData

    private val _doingSelfiePageLiveData = MutableLiveData<Boolean>()
    val onDoingSelfiePageLiveData get() = _doingSelfiePageLiveData

    private val _doingRenZhengPageLiveData = MutableLiveData<Boolean>()
    val onDoingRenZhengPageLiveData get() = _doingRenZhengPageLiveData

    private val _futureFillLiveData = MutableLiveData<List<JSONObject>>()
    val onFutureFillLiveData get() = _futureFillLiveData

    private val _allDoneLiveData = MutableLiveData<String>()
    val onAllDoneLiveData get() = _allDoneLiveData

    private val _checkMyProfileLiveData = MutableLiveData<List<JSONObject>>()
    val onCheckMyProfileLiveData get() = _checkMyProfileLiveData

    fun requestYongHuLiuCheng() {
        doPostRequest(
            path = "/X3T0BCXLgfUaCiP7Rxq8nA",
            action = hashMapOf(),
            loading = _loadingStateLiveData,
            callback = object : IApiProcessCallback {
                override fun onApiReady() {
                }

                override fun onApiDone(jsonObject: JSONObject) {
                    try {
                        val obj = jsonObject.optJSONObject("obj") ?: JSONObject()

                        // check order status
                        val shenQingStatus = obj.optString("applyStatus", "")
                        val dingDanStatus = obj.optString("orderStatus", "")

                        val checkStatus = DingDangTool.checkStatus(shenQingStatus, dingDanStatus)
                        if (checkStatus != null) {
                            checkStatus.let { page ->
                                _hasOrderStatusLiveData.value = page
                            }
                            return
                        }

                        // check all steps
                        val allSteps = obj.optJSONArray("allSteps") ?: JSONArray()
                        val allStepTitles = obj.optJSONArray("allStepTitles") ?: JSONArray()
                        val steps = obj.optJSONArray("steps") ?: JSONArray()

                        // covert to list
                        val allStepsList = mutableListOf<String>()
                        val allStepTitlesList = mutableListOf<String>()
                        val stepsList = mutableListOf<String>()

                        for (index in 0 until allSteps.length()) {
                            allStepsList.add(allSteps[index].toString().trim())
                        }

                        for (index in 0 until allStepTitles.length()) {
                            allStepTitlesList.add(allStepTitles[index].toString().trim())
                        }

                        for (index in 0 until steps.length()) {
                            stepsList.add(steps[index].toString().trim())
                        }

                        // if all steps done, return
                        val isAdType = LoginTool.filterAdType()
                        val certifyTag =
                            MyApplication.context.getString(R.string.certification_text_1)
                        if (stepsList.isEmpty()) {
                            if (!isAdType) {
                                allStepTitlesList.add(0, certifyTag)
                            }
                            _allDoneLiveData.value = allStepTitlesList.joinToString(",")
                            return
                        }
                        _allDoneLiveData.value = ""

                        // find first step
                        val firstStep = stepsList.first()
                        pageTag = firstStep

                        // if firstStep = contact_info, to contact page
                        val isLianXiRen = firstStep.contains("contact_info", true)
                        if (isLianXiRen) {
                            _doingLianXiRenPageLiveData.value = true
                            return
                        }

                        // if firstStep = account_info and is fr area, to wallet page
                        // also, check extra bang ka step
                        val extraSteps = SysConfigTool.filterExtraBangKaStep()
                        val isBangKa = firstStep.contains("account_info_xaf", true)
                        if (isBangKa or extraSteps.contains(firstStep)) {
                            _doingBangKaFrPageLiveData.value = true
                            return
                        }

                        // if firstStep = ocr_info, to document page
                        val isDocument = firstStep.contains("ocr_info", true)
                        if (isDocument) {
                            _doingDocumentPageLiveData.value = true
                            return
                        }

                        // if firstStep = selfie_info, to selfie page
                        val isSelfie = firstStep.contains("selfie_in", true)
                        if (isSelfie) {
                            _doingSelfiePageLiveData.value = true
                            return
                        }

                        // find done steps
                        val doneStepsList = mutableListOf<JSONObject>()
                        if (!isAdType) {
                            doneStepsList.add(JSONObject().apply {
                                put("title", "1.$certifyTag")
                                put("tag", certifyTag)
                            })
                        }

                        val tempStepsList1 = allStepsList.filterNot { it in stepsList }
                        for (index in tempStepsList1.indices) {
                            val element = tempStepsList1[index]
                            val eIndex = doneStepsList.size + 1
                            val ePosition = allStepsList.indexOf(element)
                            val eTitle = "${eIndex}.${allStepTitlesList[ePosition]}"
                            doneStepsList.add(JSONObject().apply {
                                put("title", eTitle)
                                put("tag", element)
                            })
                        }
                        _doneFillLiveData.value = doneStepsList

                        // find future steps
                        val futureStepsList = mutableListOf<JSONObject>()
                        val tempStepsList2 = mutableListOf<String>()
                        for (index in 1 until stepsList.size) {
                            val element = stepsList[index]
                            tempStepsList2.add(element)
                        }
                        val futureStartIndex = doneStepsList.size + 1
                        for (index in tempStepsList2.indices) {
                            val element = tempStepsList2[index]
                            val eIndex = futureStartIndex + index + 1
                            val ePosition = allStepsList.indexOf(element)
                            val eTitle = "${eIndex}.${allStepTitlesList[ePosition]}"
                            futureStepsList.add(JSONObject().apply {
                                put("title", eTitle)
                                put("tag", element)
                            })
                        }
                        _futureFillLiveData.value = futureStepsList

                        // find first step title
                        val firstStepIndex = allStepsList.indexOf(firstStep)
                        val firstStepTitle = allStepTitlesList[firstStepIndex]
                        pageTitle = firstStepTitle

                        // find fist step content
                        val firstStepContent = obj.optJSONObject(firstStep) ?: return
                        _doingRenZhengPageLiveData.value = true

                        // find fist step header and list
                        val firstStepUrl = firstStepContent.optString("apiUrl", "")
                        pageUrl = firstStepUrl

                        val firstStepDataListTemp =
                            firstStepContent.optJSONArray("dataList") ?: JSONArray()

                        // dataList covert to list type
                        val firstStepDataList = mutableListOf<JSONObject>()
                        for (index in 0 until firstStepDataListTemp.length()) {
                            val item = firstStepDataListTemp.optJSONObject(index) ?: null
                            if (item != null) {
                                firstStepDataList.add(item)
                            }
                        }

                        // combine first step header
                        val sectionTitle = "${doneStepsList.size + 1}.$firstStepTitle"
                        val fistStepHeader = JSONObject().apply {
                            put("tag", firstStep)
                            put("title", sectionTitle)
                            put("url", firstStepUrl)
                        }

                        // finish
                        _doingFillLiveData.value = Pair(fistStepHeader, firstStepDataList)

                    } catch (e: Exception) {
                        //
                    }
                }

                override fun onApiError(code: String, errMsg: String) {
                }

            })
    }

    fun requestYongHuLiuChengForCheckMyProfile() {
        doPostRequest(
            path = "/X3T0BCXLgfUaCiP7Rxq8nA",
            action = hashMapOf(),
            loading = _loadingStateLiveData,
            callback = object : IApiProcessCallback {
                override fun onApiReady() {
                }

                override fun onApiDone(jsonObject: JSONObject) {
                    try {
                        val obj = jsonObject.optJSONObject("obj") ?: JSONObject()

                        // check all steps
                        val allSteps = obj.optJSONArray("allSteps") ?: JSONArray()
                        val allStepTitles = obj.optJSONArray("allStepTitles") ?: JSONArray()
                        val steps = obj.optJSONArray("steps") ?: JSONArray()

                        // covert to list
                        val allStepsList = mutableListOf<String>()
                        val allStepTitlesList = mutableListOf<String>()
                        val stepsList = mutableListOf<String>()

                        for (index in 0 until allSteps.length()) {
                            allStepsList.add(allSteps[index].toString().trim())
                        }

                        for (index in 0 until allStepTitles.length()) {
                            allStepTitlesList.add(allStepTitles[index].toString().trim())
                        }

                        for (index in 0 until steps.length()) {
                            stepsList.add(steps[index].toString().trim())
                        }

                        val list = mutableListOf<JSONObject>()

                        val isAdType = LoginTool.filterAdType()
                        val certifyTag =
                            MyApplication.context.getString(R.string.certification_text_1)
                        if (!isAdType) {
                            val item = JSONObject().apply {
                                put("title", "1.$certifyTag")
                                put("done", LoginTool.didCertify)
                            }
                            list.add(item)
                        }

                        for (index in allStepTitlesList.indices) {
                            val step = allStepsList[index]
                            val title = allStepTitlesList[index]
                            val isExit = stepsList.any { it == step }
                            val done = !isExit

                            val item = JSONObject().apply {
                                put("title", "${list.size + 1}.$title")
                                put("done", done)
                            }
                            list.add(item)
                        }
                        _checkMyProfileLiveData.value = list

                    } catch (e: Exception) {
                        //
                    }
                }

                override fun onApiError(code: String, errMsg: String) {
                }

            })
    }

    fun requestYongHuLiuChengForLianXiRen() {
        doPostRequest(
            path = "/X3T0BCXLgfUaCiP7Rxq8nA",
            action = hashMapOf(),
            loading = _loadingStateLiveData,
            callback = object : IApiProcessCallback {
                override fun onApiReady() {
                }

                override fun onApiDone(jsonObject: JSONObject) {
                    try {
                        val obj = jsonObject.optJSONObject("obj") ?: JSONObject()

                        // check order status
                        val shenQingStatus = obj.optString("applyStatus", "")
                        val dingDanStatus = obj.optString("orderStatus", "")

                        val checkStatus = DingDangTool.checkStatus(shenQingStatus, dingDanStatus)
                        if (checkStatus != null) {
                            checkStatus.let { page ->
                                _hasOrderStatusLiveData.value = page
                            }
                            return
                        }

                        // check all steps
                        val allSteps = obj.optJSONArray("allSteps") ?: JSONArray()
                        val allStepTitles = obj.optJSONArray("allStepTitles") ?: JSONArray()
                        val steps = obj.optJSONArray("steps") ?: JSONArray()

                        // covert to list
                        val allStepsList = mutableListOf<String>()
                        val allStepTitlesList = mutableListOf<String>()
                        val stepsList = mutableListOf<String>()

                        for (index in 0 until allSteps.length()) {
                            allStepsList.add(allSteps[index].toString().trim())
                        }

                        for (index in 0 until allStepTitles.length()) {
                            allStepTitlesList.add(allStepTitles[index].toString().trim())
                        }

                        for (index in 0 until steps.length()) {
                            stepsList.add(steps[index].toString().trim())
                        }

                        // if all steps done, return
                        val isAdType = LoginTool.filterAdType()
                        val certifyTag =
                            MyApplication.context.getString(R.string.certification_text_1)
                        if (stepsList.isEmpty()) {
                            if (!isAdType) {
                                allStepTitlesList.add(0, certifyTag)
                            }
                            _allDoneLiveData.value = allStepTitlesList.joinToString(",")
                            return
                        }
                        _allDoneLiveData.value = ""

                        // find first step
                        val firstStep = stepsList.first()
                        pageTag = firstStep

                        // if firstStep = account_info and is fr area, to wallet page
                        // also, check extra bang ka step
                        val extraSteps = SysConfigTool.filterExtraBangKaStep()
                        val isBangKa = firstStep.contains("account_info_xaf", true)
                        if (isBangKa or extraSteps.contains(firstStep)) {
                            _doingBangKaFrPageLiveData.value = true
                            return
                        }

                        // if firstStep = ocr_info, to document page
                        val isDocument = firstStep.contains("ocr_info", true)
                        if (isDocument) {
                            _doingDocumentPageLiveData.value = true
                            return
                        }

                        // if firstStep = selfie_info, to selfie page
                        val isSelfie = firstStep.contains("selfie_in", true)
                        if (isSelfie) {
                            _doingSelfiePageLiveData.value = true
                            return
                        }

                        // if firstStep != contact_info, to ren zheng page
                        val isRenZheng = firstStep.contains("contact_info", true)
                        if (!isRenZheng) {
                            _doingRenZhengPageLiveData.value = true
                            return
                        }

                        // find done steps
                        val doneStepsList = mutableListOf<JSONObject>()
                        if (!isAdType) {
                            doneStepsList.add(JSONObject().apply {
                                put("title", "1.$certifyTag")
                                put("tag", certifyTag)
                            })
                        }

                        val tempStepsList1 = allStepsList.filterNot { it in stepsList }
                        for (index in tempStepsList1.indices) {
                            val element = tempStepsList1[index]
                            val eIndex = doneStepsList.size + 1
                            val ePosition = allStepsList.indexOf(element)
                            val eTitle = "${eIndex}.${allStepTitlesList[ePosition]}"
                            doneStepsList.add(JSONObject().apply {
                                put("title", eTitle)
                                put("tag", element)
                            })
                        }
                        _doneFillLiveData.value = doneStepsList

                        // find future steps
                        val futureStepsList = mutableListOf<JSONObject>()
                        val tempStepsList2 = mutableListOf<String>()
                        for (index in 1 until stepsList.size) {
                            val element = stepsList[index]
                            tempStepsList2.add(element)
                        }
                        val futureStartIndex = doneStepsList.size + 1
                        for (index in tempStepsList2.indices) {
                            val element = tempStepsList2[index]
                            val eIndex = futureStartIndex + index + 1
                            val ePosition = allStepsList.indexOf(element)
                            val eTitle = "${eIndex}.${allStepTitlesList[ePosition]}"
                            futureStepsList.add(JSONObject().apply {
                                put("title", eTitle)
                                put("tag", element)
                            })
                        }
                        _futureFillLiveData.value = futureStepsList

                        // find first step title
                        val firstStepIndex = allStepsList.indexOf(firstStep)
                        val firstStepTitle = allStepTitlesList[firstStepIndex]
                        pageTitle = firstStepTitle

                        // find fist step content
                        val firstStepContent = obj.optJSONObject(firstStep) ?: return

                        // find fist step header and list
                        val firstStepUrl = firstStepContent.optString("apiUrl", "")
                        pageUrl = firstStepUrl

                        val firstStepDataListTemp =
                            firstStepContent.optJSONArray("dataList") ?: JSONArray()

                        val firstStepRelationShipsTemp =
                            firstStepContent.optJSONArray("relationShips") ?: JSONArray()

                        // find need render counts
                        val itemCount = firstStepContent.optInt("itemCount", 0)
                        val firstStepDataList = mutableListOf<List<JSONObject>>()
                        for (index in 0 until itemCount) {
                            val subStepDataList = mutableListOf<JSONObject>()
                            for (subIndex in 0 until firstStepDataListTemp.length()) {
                                val item = firstStepDataListTemp.optJSONObject(subIndex) ?: null
                                if (item != null) {
                                    val newItem = JSONObject(item.toString())

                                    // if is relationship action, need initial values
                                    val action = newItem.optString("action", "")
                                    if (action.contains("CONTACT_GROUP_RELATION", true)) {
                                        if (firstStepRelationShipsTemp.length() > index) {
                                            val shipsTemp =
                                                firstStepRelationShipsTemp.optJSONArray(index)
                                            val ships = JSONArray()
                                            for (relaIndex in 0 until shipsTemp.length()) {
                                                val relation = shipsTemp.optString(relaIndex, "")
                                                if (relation.isNotBlank()) {
                                                    ships.put(JSONObject().apply {
                                                        put("title", relation)
                                                        put("value", relation)
                                                    })
                                                }
                                            }
                                            newItem.put("values", ships)
                                        }
                                    }
                                    subStepDataList.add(newItem)
                                }
                            }

                            firstStepDataList.add(subStepDataList)
                        }

                        // combine first step header
                        val sectionTitle = "${doneStepsList.size + 1}.$firstStepTitle"
                        val fistStepHeader = JSONObject().apply {
                            put("tag", firstStep)
                            put("title", sectionTitle)
                            put("url", firstStepUrl)
                        }

                        _doingLianXiRenFillLiveData.value = Pair(fistStepHeader, firstStepDataList)

                    } catch (e: Exception) {
                        //
                    }
                }

                override fun onApiError(code: String, errMsg: String) {
                }

            })
    }

    fun requestYongHuLiuChengForBangKa() {
        doPostRequest(
            path = "/X3T0BCXLgfUaCiP7Rxq8nA",
            action = hashMapOf(),
            loading = _loadingStateLiveData,
            callback = object : IApiProcessCallback {
                override fun onApiReady() {
                }

                override fun onApiDone(jsonObject: JSONObject) {
                    try {
                        val obj = jsonObject.optJSONObject("obj") ?: JSONObject()

                        // check order status
                        val shenQingStatus = obj.optString("applyStatus", "")
                        val dingDanStatus = obj.optString("orderStatus", "")

                        val checkStatus = DingDangTool.checkStatus(shenQingStatus, dingDanStatus)
                        if (checkStatus != null) {
                            checkStatus.let { page ->
                                _hasOrderStatusLiveData.value = page
                            }
                            return
                        }

                        // check all steps
                        val allSteps = obj.optJSONArray("allSteps") ?: JSONArray()
                        val allStepTitles = obj.optJSONArray("allStepTitles") ?: JSONArray()
                        val steps = obj.optJSONArray("steps") ?: JSONArray()

                        // covert to list
                        val allStepsList = mutableListOf<String>()
                        val allStepTitlesList = mutableListOf<String>()
                        val stepsList = mutableListOf<String>()

                        for (index in 0 until allSteps.length()) {
                            allStepsList.add(allSteps[index].toString().trim())
                        }

                        for (index in 0 until allStepTitles.length()) {
                            allStepTitlesList.add(allStepTitles[index].toString().trim())
                        }

                        for (index in 0 until steps.length()) {
                            stepsList.add(steps[index].toString().trim())
                        }

                        // if all steps done, return
                        val isAdType = LoginTool.filterAdType()
                        val certifyTag =
                            MyApplication.context.getString(R.string.certification_text_1)
                        if (stepsList.isEmpty()) {
                            if (!isAdType) {
                                allStepTitlesList.add(0, certifyTag)
                            }
                            _allDoneLiveData.value = allStepTitlesList.joinToString(",")
                            return
                        }
                        _allDoneLiveData.value = ""

                        // find first step
                        val firstStep = stepsList.first()
                        pageTag = firstStep

                        // if firstStep = account_info and is fr area, to wallet page
                        // also, check extra bang ka step
                        val extraSteps = SysConfigTool.filterExtraBangKaStep()
                        val isBangKa = firstStep.contains("account_info_xaf", true)
                        if (isBangKa or extraSteps.contains(firstStep)) {
                            _doingBangKaFrPageLiveData.value = true
                            return
                        }

                        // if firstStep = ocr_info, to document page
                        val isDocument = firstStep.contains("ocr_info", true)
                        if (isDocument) {
                            _doingDocumentPageLiveData.value = true
                            return
                        }

                        // if firstStep = selfie_info, to selfie page
                        val isSelfie = firstStep.contains("selfie_in", true)
                        if (isSelfie) {
                            _doingSelfiePageLiveData.value = true
                            return
                        }

                        // if firstStep != contact_info, to ren zheng page
                        val isRenZheng = firstStep.contains("contact_info", true)
                        if (!isRenZheng) {
                            _doingRenZhengPageLiveData.value = true
                            return
                        }

                        // find done steps
                        val doneStepsList = mutableListOf<JSONObject>()
                        if (!isAdType) {
                            doneStepsList.add(JSONObject().apply {
                                put("title", "1.$certifyTag")
                                put("tag", certifyTag)
                            })
                        }

                        val tempStepsList1 = allStepsList.filterNot { it in stepsList }
                        for (index in tempStepsList1.indices) {
                            val element = tempStepsList1[index]
                            val eIndex = doneStepsList.size + 1
                            val ePosition = allStepsList.indexOf(element)
                            val eTitle = "${eIndex}.${allStepTitlesList[ePosition]}"
                            doneStepsList.add(JSONObject().apply {
                                put("title", eTitle)
                                put("tag", element)
                            })
                        }
                        _doneFillLiveData.value = doneStepsList

                        // find future steps
                        val futureStepsList = mutableListOf<JSONObject>()
                        val tempStepsList2 = mutableListOf<String>()
                        for (index in 1 until stepsList.size) {
                            val element = stepsList[index]
                            tempStepsList2.add(element)
                        }
                        val futureStartIndex = doneStepsList.size + 1
                        for (index in tempStepsList2.indices) {
                            val element = tempStepsList2[index]
                            val eIndex = futureStartIndex + index + 1
                            val ePosition = allStepsList.indexOf(element)
                            val eTitle = "${eIndex}.${allStepTitlesList[ePosition]}"
                            futureStepsList.add(JSONObject().apply {
                                put("title", eTitle)
                                put("tag", element)
                            })
                        }
                        _futureFillLiveData.value = futureStepsList

                        // find first step title
                        val firstStepIndex = allStepsList.indexOf(firstStep)
                        val firstStepTitle = allStepTitlesList[firstStepIndex]
                        pageTitle = firstStepTitle

                        // find fist step content
                        val firstStepContent = obj.optJSONObject(firstStep) ?: return

                        // find fist step header and list
                        val firstStepUrl = firstStepContent.optString("apiUrl", "")
                        pageUrl = firstStepUrl

                        // combine first step header
                        val sectionTitle = "${doneStepsList.size + 1}.$firstStepTitle"
                        val fistStepHeader = JSONObject().apply {
                            put("tag", firstStep)
                            put("title", sectionTitle)
                            put("url", firstStepUrl)
                        }

                        // finish
                        _doingBangKaFillLiveData.value = fistStepHeader

                    } catch (e: Exception) {
                        //
                    }
                }

                override fun onApiError(code: String, errMsg: String) {
                }

            })
    }

    fun requestUpdateYongHuLiuCheng(params: HashMap<String, Any>) {
        val path = _doingFillLiveData.value?.first?.optString("url", "") ?: ""
        doPostRequest(
            path = path,
            action = params,
            loading = _loadingStateLiveData,
            callback = object : IApiProcessCallback {
                override fun onApiReady() {
                }

                override fun onApiDone(jsonObject: JSONObject) {
                    requestYongHuLiuCheng()
                }

                override fun onApiError(code: String, errMsg: String) {
                }
            })
    }

    fun requestUpdateYongHuLiuChengForLianXiRen(params: List<HashMap<String, Any>>) {
        val path = _doingLianXiRenFillLiveData.value?.first?.optString("url", "") ?: ""
        val parameterName =
            _doingLianXiRenFillLiveData.value?.first?.optString("contactParamName", "contactList")
                ?: ""
        val paramsFormat = hashMapOf<String, Any>().apply {
            put(parameterName, params)
        }
        doPostRequest(
            path = path,
            action = paramsFormat,
            loading = _loadingStateLiveData,
            callback = object : IApiProcessCallback {
                override fun onApiReady() {
                }

                override fun onApiDone(jsonObject: JSONObject) {
                    requestYongHuLiuChengForLianXiRen()
                }

                override fun onApiError(code: String, errMsg: String) {
                }
            })
    }

    fun updateDoneTitles(value: String) {
        if (value.isNotBlank()) {
            val array = value.split(",")
            val doneStepsList = mutableListOf<JSONObject>()
            for (index in array.indices) {
                val element = array[index]
                val eIndex = index + 1
                val eTitle = "${eIndex}.$element"
                doneStepsList.add(JSONObject().apply {
                    put("title", eTitle)
                    put("tag", element)
                })
            }
            _doneFillLiveData.value = doneStepsList
        }
    }
}